      subroutine readwebs

      !!read scenario design information from webs.webs created by
      !!WEBs Interface
      !!Zhiqiang, 2012-10-16

      use parm

      character (len=80) :: titldum
      integer :: fileStat
      logical :: alive
      integer :: eof

      fileStat = 0
      webs_base = -1 !-1 - no webs file
                     ! 0 - base scenario is historical
                     ! 1 - base scenario is conventional
      webs_tillage_cnop = -1   ! the tillage swat id
                               ! conventional - 56
                               ! zero till - 4
      webs_tillage_cnop = 1.0  ! the cnop for selected tillage type
                               ! conventional - 1.1
                               ! zero till - 1.02
      webs_small_dam_num = 0   ! small dams selected in scenario design
      webs_holding_pond_num = 0! holding ponds selected in scenario design
      webs_holding_pond_hru_num = 0 ! holding pond hrus selected in scenario design
      webs_grazing_hru_num = 0 ! grazing hrus selected in scenario design
      webs_tillage_hru_num = 0 ! tillage hrus selected in scenario design
      webs_forage_hru_num = 0  ! forage converstion hrus selected in scenario design

      output_test_information = .TRUE. !true - output webs.test
                                       !false - don't output webs.test

      if(output_test_information) then
          open(2011,file="webs.test")
      end if

      inquire(file="webs.webs",exist=alive)
      if(.NOT. alive) return;

      open(2010,file="webs.webs",iostat=fileStat, status='OLD')
      if(fileStat > 0) return
      if(fileStat < 0) return

      read (2010,5101,iostat=eof) titldum !read
      if(eof < 0) return

      !WEBs Scenario database
      read (2010,5101,iostat=eof) titldum
      if(eof < 0) return

      read (2010,5102,iostat=eof) webs_database
      if(eof < 0) return

      !base scenario
      read (2010,5101,iostat=eof) titldum
      if(eof < 0) return

      read (2010,*,iostat=eof)    webs_base
      if(eof < 0) return

      !small dam
      read (2010,5101,iostat=eof) titldum
      if(eof < 0) return
      read (2010,*,iostat=eof)    webs_small_dam_num
      if(eof < 0) return
      if(webs_small_dam_num > 0) then
        allocate (webs_small_dam(webs_small_dam_num))
        read (2010, *,iostat=eof)   webs_small_dam
        if(eof < 0) return
      else
        read (2010,5101,iostat=eof) titldum
        if(eof < 0) return
      end if

      !holding pond / point source
      read (2010,5101,iostat=eof) titldum
      if(eof < 0) return

      !holding pond ID
      read (2010,5101,iostat=eof) titldum
      if(eof < 0) return
      read (2010,*,iostat=eof)    webs_holding_pond_num
      if(eof < 0) return
      if(webs_holding_pond_num > 0) then
        allocate (webs_holding_pond(webs_holding_pond_num))
        read (2010, *,iostat=eof)   webs_holding_pond
        if(eof < 0) return
      else
        read (2010,5101,iostat=eof) titldum
        if(eof < 0) return
      end if

      !holding pond HRU
      read (2010,5101,iostat=eof) titldum
      if(eof < 0) return
      read (2010,*,iostat=eof)    webs_holding_pond_hru_num
      if(webs_holding_pond_hru_num > 0) then
        allocate (webs_holding_pond_hru(webs_holding_pond_hru_num))
        read (2010, *,iostat=eof)   webs_holding_pond_hru
        if(eof < 0) return
      else
        read (2010,5101,iostat=eof) titldum
        if(eof < 0) return
      end if

      !Grazing
      read (2010,5101,iostat=eof) titldum
      if(eof < 0) return
      read (2010,*,iostat=eof)    webs_grazing_hru_num
      if(eof < 0) return
      if(webs_grazing_hru_num > 0) then
        allocate (webs_grazing_hru(webs_grazing_hru_num))
        read (2010, *,iostat=eof)   webs_grazing_hru
        if(eof < 0) return
      else
        read (2010,5101,iostat=eof) titldum
        if(eof < 0) return
      end if

      !Tillage
      read (2010,5101,iostat=eof) titldum
      if(eof < 0) return
      !Tillage Type
      read (2010,5101,iostat=eof) titldum
      if(eof < 0) return
      read (2010,*,iostat=eof)    webs_tillage_type, webs_tillage_cnop
      if(eof < 0) return

      !Tillage HRU
      read (2010,5101,iostat=eof) titldum
      if(eof < 0) return
      read (2010,*,iostat=eof)    webs_tillage_hru_num
      if(eof < 0) return
      if(webs_tillage_hru_num > 0) then
        allocate (webs_tillage_hru(webs_tillage_hru_num))
        read (2010, *,iostat=eof)   webs_tillage_hru
        if(eof < 0) return
      else
        read (2010,5101,iostat=eof) titldum
        if(eof < 0) return
      end if

      !Forage Conversion
      read (2010,5101,iostat=eof) titldum
      if(eof < 0) return
      read (2010,*,iostat=eof)    webs_forage_hru_num
      if(eof < 0) return
      if(webs_forage_hru_num > 0) then
        allocate (webs_forage_hru(webs_forage_hru_num))
        read (2010, *,iostat=eof)   webs_forage_hru
        if(eof < 0) return
      else
        read (2010,5101,iostat=eof) titldum
        if(eof < 0) return
      end if

      close(2010)

      if(output_test_information) then
          write(2011,*) "web.webs is good!"
      end if

 5101 format (a80)
 5102 format (a1000)

      end
